        TTL     > TOS11 - Default vectors, OSCLI and padding

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Use OS_Wrch to save confusion !

vstring ROUT

        PLA
        STA     vstrptr
        PLA
        STA     vstrptr+1
        LDYIM   0
        STY     vstrptr+turbo
        INY

10      LDAIY   vstrptr
        CMPIM   cNOP
        BEQ     #FT90
        JSR     oswrch
        INY
        BNE     #BT10

90      TYA
        CLC
        ADC     vstrptr
        TAX
        LDAIM   0
        ADC     vstrptr+1
        PHA
        TXA
        PHA

anrts   RTS

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; In    YX -> string

xystring ROUT

        STX     vstrptr
        STY     vstrptr+1
        LDYIM   0
        STY     vstrptr+turbo

10      LDAIY   vstrptr
        CMPIM   " "
        BCC     #FT90
        JSR     oswrch
        INY
        BNE     #BT10

90      RTS

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

badbrk  BRK
        =       0
        =       "Unsupported", 0

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        ^       vectors
vecsstart
userv   #       2
        &       badbrk ; userv

brkv    #       2
        &       tim_brk

irq1v   #       2
        &       irq1han

irq2v   #       2
        &       badbrk ; irq2v

cliv    #       2
        &       tim_cli

bytev   #       2
        &       tim_byte

wordv   #       2
        &       tim_word

wrchv   #       2
        &       tim_wrch

rdchv   #       2
        &       tim_rdch

filev   #       2
        &       tim_file

argsv   #       2
        &       tim_args

bgetv   #       2
        &       tim_bget

bputv   #       2
        &       tim_bput

gbpbv   #       2
        &       tim_gbpb

findv   #       2
        &       tim_find

fscv    #       2
        &       badbrk ; fscv

eventv  #       2
        &       anrts  ; eventv

uptv    #       2
        &       anrts  ; uptv (simulate printer busy)

netv    #       2
        &       anrts  ; netv (ditto)

vduv    #       2
        &       badbrk ; vduv

keyv    #       2
        &       badbrk ; keyv

insv    #       2
        &       badbrk ; insv

remv    #       2
        &       badbrk ; remv

cnpv    #       2
        &       badbrk ; cnpv

ind1v   #       2
        &       anrts  ; ind1v

ind2v   #       2
        &       anrts  ; ind2v

ind3v   #       2
        &       anrts  ; ind3v
vecsend

veclen  *       vecsend-vecsstart

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Stick up here so we can easily patch another language in instead of BASIC

tim_cli ROUT

        STX     cliptr
        STY     cliptr+1
 [ $debugcli
        JSR     xystring
        JSR     osnewl
 ]
        LDYIM   0
        STY     cliptr+turbo

; Must copy away into our buffer so osargs can see it

10      LDAIY   cliptr
        STAAY   myclibuffer
        CMPIM   CR
        BEQ     #FT20
        INY
        BNE     #BT10
15      RTS                     ; Return if string too long. (cf pbMOS)


20      LDXIM   :LSB: myclibuffer ; Point cliptr at our new buffer
        LDYIM   :MSB: myclibuffer
        STX     cliptr
        STY     cliptr+1

        LDXIM   0
        LDYIM   &FF
30      JSR     skips_next
        CMPIM   "*"
        BEQ     #BT30

        CMPIM   CR              ; Totally null ?
        BEQ     #BT15
        CMPIM   "|"             ; Or a comment ?
        BEQ     #BT15

        CLC                     ; Write address of first ~space, ~* into cliptr
        TYA
        ADC     cliptr
        STA     cliptr
        BCC     #FT40
        INC     cliptr+1
40
        LDYIM   0               ; New ptr complete

        LDAIY   cliptr          ; Get char again. Confidence test
        CMPIM   "."
        BEQ     notourcommand

scanthiscomloop
        TYA
        PHA
        JSR     skipspaces

checkcomloop
        LDAAX   comtable
        BMI     endofourword
        EORIY   cliptr
        ANDIM   &DF
        BNE     nomatch
        INX
        INY
        BRA     checkcomloop

nomatch LDAIY   cliptr
        INY
        CMPIM   "."
        BEQ     goodmatch

badmatch
        PLA
        TAY
        SEC
        BRA     skiptoend

endofourword
        ASLA
        BMI     goodmatch
        LDAIY   cliptr
        CMPIM   "A"             ; Allows BASIC. BASIC1 etc for pB compatibility
        BCS     badmatch

goodmatch
        PLA
        CLC

skiptoend
        DEX

skipt_loop
        INX
        LDAAX   comtable
        BPL     skipt_loop
        BCC     foundmatch
        INX
        LDAAX   comtable
        BNE     scanthiscomloop
        BEQ     notourcommand

foundmatch
        ASLA
        ANDIM   &7F
        TAX
        JSR     pushcommand
        BCC     okcommand

notourcommand
        LDX     cliptr
        LDY     cliptr+1
        =       sv_cli

okcommand
        RTS


pushcommand
        LDAAX   comrouts+1
        PHA
        LDAAX   comrouts
        PHA
        RTS

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

skips_next
        INY
skipspaces
        LDAIY   cliptr
        CMPIM   " "
        BEQ     skips_next
        CMPIM   CR
        RTS

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

comrouts
        &       language_star-1         ; 00
        &       quit_star-1             ; 01
        &       help_star-1             ; 02
        &       go_star-1               ; 03
        &       titlethenloop_star-1    ; 04
        &       page_star-1             ; 05

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

myclibuffer %   256

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        %       3 :AND: (-.)            ; ALIGN 4

padlength * (fixedcode-.) :AND: :NOT: 3

 [ padlength >= 8
        =       "tutu"                  ; Magic word so Glue code finds space !
        &       padlength               ; 32 bit number !
        &       0
 ]

; Don't actually pad out ... we may get 'Code overflowing source' error !!!

 ! 0, "Padlength = ":CC:(:STR:padlength):CC:" bytes"


 ASSERT fixedcode >= .

        LNK     TOS12
